
//提交单订
function submitpay(goods) {
	$('#submit').attr('disabled',true);
	//获取收件人地址ID
	//获取支付方式ID
	//alert($('input[name=address]:checked').val());
	//alert($('input[name=payfs]:checked').val());
	var addressid = $('input[name=address]:checked').val();
	var payid = $('input[name=payfs]:checked').val();
	$.post("ajax/incar.php", {
		eve: 4 //表示修改购物车数量
		,gids: goods
		,address: addressid
		,pay: payid
	}, function(data, textStatus, reXML) {
		//var obj = eval(data);
		//alert(data);
		var obj = eval(data);
		//alert(obj.newsid);
		if(obj.eve == 1){
			//提交成功处理
			alert("购买成功:"+obj.newsid);
			location.href = "uorders.php?orderid="+obj.newsid;
		}else{
			alert('提交订单失败!');
		}
	
	}, "text");
}

//评价商品
function goEvaluate(sid,gid,obj){
	var centent = $(obj).parent().text();
	$.post("ajax/incar.php", {
		eve: 6 //表示修改购物车数量
		,sid: sid
		,gid: gid
		,centent: centent
	}, function(data, textStatus, reXML) {
		//var obj = eval(data);
		//alert(data);
		if(data == 1){
			//alert('aaaa');
			$(obj).parent().removeAttr('contenteditable');
			$(obj).remove();
		}
		
		
		/*var obj = eval(data);
		//alert(obj.newsid);
		if(obj.eve == 1){
			//提交成功处理
			alert("购买成功:"+obj.newsid);
			location.href = "uorders.php?orderid="+obj.newsid;
		}else{
			alert('提交订单失败!');
		}*/
	
	}, "text");
}

var exparr = new Array();
var expzt = new Array("在途，即货物处于运输过程中；"
	,"揽件，货物已由快递公司揽收并且产生了第一条跟踪信息；"
	,"疑难，货物寄送过程出了问题；"
	,"签收，收件人已签收；"
	,"退签，即货物由于用户拒签、超区等原因退回，而且发件人已经签收；"
	,"派件，即快递正在进行同城派件；"
	,"退回，货物正处于退回发件人的途中；");
	
var expcom = {
	    'shunfeng':'顺丰',
        'yuantong':'圆通速递',
        'shentong':'申通',
        'yunda':'韵达快运',
        'ems':'ems快递',
        'tiantian':'天天快递',
        'zhaijisong':'宅急送',
        'quanfengkuaidi':'全峰快递',
        'zhongtong':'中通速递',
        'rufengda':'如风达',
        'debangwuliu':'德邦物流',
        'huitongkuaidi':'汇通快运',
        'aae':'aae全球专递',
        'anjie':'安捷快递',
        'anxindakuaixi':'安信达快递',
        'biaojikuaidi':'彪记快递',
        'bht':'bht',
        'baifudongfang':'百福东方国际物流',
        'coe':'中国东方（COE）',
        'changyuwuliu':'长宇物流',
        'datianwuliu':'大田物流',
        'dhl':'dhl',
        'dpex':'dpex',
        'dsukuaidi':'d速快递',
        'disifang':'递四方',
        'fedex':'fedex（国外）',
        'feikangda':'飞康达物流',
        'fenghuangkuaidi':'凤凰快递',
        'feikuaida':'飞快达',
        'guotongkuaidi':'国通快递',
        'ganzhongnengda':'港中能达物流',
        'guangdongyouzhengwuliu':'广东邮政物流',
        'gongsuda':'共速达',
        'hengluwuliu':'恒路物流',
        'huaxialongwuliu':'华夏龙物流',
        'haihongwangsong':'海红',
        'haiwaihuanqiu':'海外环球',
        'jiayiwuliu':'佳怡物流',
        'jinguangsudikuaijian':'京广速递',
        'jixianda':'急先达',
        'jjwl':'佳吉物流',
        'jymwl':'加运美物流',
        'jindawuliu':'金大物流',
        'jialidatong':'嘉里大通',
        'jykd':'晋越快递',
        'kuaijiesudi':'快捷速递',
        'lianb':'联邦快递（国内）',
        'lianhaowuliu':'联昊通物流',
        'longbanwuliu':'龙邦物流',
        'lijisong':'立即送',
        'lejiedi':'乐捷递',
        'minghangkuaidi':'民航快递',
        'meiguokuaidi':'美国快递',
        'menduimen':'门对门',
        'ocs':'OCS',
        'peisihuoyunkuaidi':'配思货运',
        'quanchenkuaidi':'全晨快递',
        'quanjitong':'全际通物流',
        'quanritongkuaidi':'全日通快递',
        'quanyikuaidi':'全一快递',
        'santaisudi':'三态速递',
        'shenghuiwuliu':'盛辉物流',
        'sue':'速尔物流',
        'shengfeng':'盛丰物流',
        'saiaodi':'赛澳递',
        'tiandihuayu':'天地华宇',
        'tnt':'tnt',
        'ups':'ups',
        'wanjiawuliu':'万家物流',
        'wenjiesudi':'文捷航空速递',
        'wuyuan':'伍圆',
        'wxwl':'万象物流',
        'xinbangwuliu':'新邦物流',
        'xinfengwuliu':'信丰物流',
        'yafengsudi':'亚风速递',
        'yibangwuliu':'一邦速递',
        'youshuwuliu':'优速物流',
        'youzhengguonei':'邮政包裹挂号信',
        'youzhengguoji':'邮政国际包裹挂号信',
        'yuanchengwuliu':'远成物流',
        'yuanweifeng':'源伟丰快递',
        'yuanzhijiecheng':'元智捷诚快递',
        'yuntongkuaidi':'运通快递',
        'yuefengwuliu':'越丰物流',
        'yad':'源安达',
        'yinjiesudi':'银捷速递',
        'zhongtiekuaiyun':'中铁快运',
        'zhongyouwuliu':'中邮物流',
        'zhongxinda':'忠信达',
        'zhimakaimen':'芝麻开门'
};

$(function(){
	//!确认收货
	$('#uorder').on('click','.payover',function(){
		//alert('已收货');
		var sid = $(this).parent().parent().siblings('.ssid').text();
		$.post("ajax/incar.php",{
			eve: 11 //11为确认收货
			,sid: sid
		},function(data, textStatus, reXML){
			if(data == 1){
				$('#uorder').load(location.href+" #uorder>*","")
				alert('收货成功!');
			}else{
				alert(data);
			}
		},"text");
		
	});
	//显示物流详情
	$('#uorder').on('mouseover','.exp_info',function(){
		//alert($(this).text());
		//
		var showdiv = $('.show_express');
		var expid = $(this).text();
		showdiv.css('top',$(this).offset().top+$(this).height());
		showdiv.show();
		//进行AJAX请求得到快递信息
		
		if(!exparr.hasOwnProperty(expid)){
			$.post('ajax/test_express.php',{
				expid: expid
			},function(data){
				//alert(data);
				var dataObj = eval('('+data+')');
				//alert(dataObj.message);
				//200表示成功
				if(dataObj.status == 200){
					
					showdiv.children('ul').remove();
					//alert(dataObj.message);
					var ul = $("<ul class='showing' style='font-size:12px;margin:15px'></ul>");
					var li = $('<li>单号：'+dataObj.nu+'</li>');
					ul.append(li);
					li = $('<li>状态：'+expzt[dataObj.state]+'</li>');
					ul.append(li);
					li = $('<li>快递公司：'+expcom[dataObj.com]+'</li>');
					ul.append(li);
					ul.append($('<hr />'));
					
					var i = 0;
					for(var dkey in dataObj.data){
						//alert( dataObj.data[dkey].context + '['+dataObj.data[dkey].time+']');//弹出所有内容
						if(i == 0){
							li = $('<li style="font-weight: bold; color: orangered;">['+dataObj.data[dkey].time+'] '+dataObj.data[dkey].context+' </li>');
						}else{
							li = $('<li>['+dataObj.data[dkey].time+'] '+dataObj.data[dkey].context+' </li>');
						}
						
						ul.append(li);
						exparr[expid] = ul;
						showdiv.append(ul);
						i++;
					}
				}else{
					
				}
			},"text");
		}else{
			//alert('aaabbb');
			showdiv.children('ul').remove();
			showdiv.append(exparr[expid]);
		}
		
		
	});
	
	$('#uorder').on('mouseout','.exp_info',function(){
		var showdiv = $('.show_express');
		showdiv.hide();
		showdiv.children('ul').remove();
		var ul = $('<ul class="showing"><img src="images/ajax-white.gif" width="16px" height="16px"/><span>正在加载...</span></ul>');
		showdiv.append(ul);
	});
	
});
